﻿using System;
using System.IO;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;

namespace PickGold.Nulls
{
	/// <summary>
	/// NullEnumerator
	/// </summary>
	public sealed class NullEnumerator : IEnumerator
	{
		/// <summary>
		/// 唯一实例
		/// </summary>
		public readonly static IEnumerator Value = new NullEnumerator();

		private NullEnumerator()
		{
			if (Value != null)
				throw new InvalidOperationException();
		}

		object IEnumerator.Current
		{
			get
			{
				return null;
			}
		}

		bool IEnumerator.MoveNext()
		{
			return false;
		}

		void IEnumerator.Reset()
		{
		}
	}

	/// <summary>
	/// NullEnumerator
	/// </summary>
	public sealed class NullEnumerator<T> : IEnumerator<T>
	{
		/// <summary>
		/// 唯一实例
		/// </summary>
		public readonly static IEnumerator<T> Value = new NullEnumerator<T>();

		private NullEnumerator()
		{
			if (Value != null)
				throw new InvalidOperationException();
		}

		T IEnumerator<T>.Current
		{
			get
			{
				return Reflector<T>.DefaultValue;
			}
		}

		void IDisposable.Dispose()
		{
		}

		object IEnumerator.Current
		{
			get
			{
				return Reflector<T>.DefaultValue;
			}
		}

		bool IEnumerator.MoveNext()
		{
			return false;
		}

		void IEnumerator.Reset()
		{
		}
	}
}
